package com.hss.rxjava.result;


import com.hss.rxjava.CheckInterface;

/**
 * 
 * @ClassName: ResultBaseObject 
 * @Description: TODO(泛型返回) 
 * @author (黄赛赛)
 * @date 2016-3-25 上午10:22:10 
 * 
 * @param <T>
 */
public class ResultObject<T> extends ResultBaseBean {
	public T response;

	public T getResponse() {
		return response;
	}

	public void setResponse(T response) {
		this.response = response;
	}


	/**
	 * 检查数据完整性
	 * @param index 0 默认检查方式
	 * @return
	 */
	public boolean check(boolean notNull,int index) {
		if(notNull){
			return response != null && checkAndFix(index);
		}else{
			return response == null || checkAndFix(index);
		}
	}

	private boolean checkAndFix(int index){
		if(response instanceof CheckInterface){
			if(!((CheckInterface) response).check(index)){
				((CheckInterface) response).fix(index);
				if(!((CheckInterface) response).check(index)) return false;
			}
		}
		return true;
	}
}
